How to Sort Search Results

About Sorting in SmartHub

By default, SmartHub enables users to filter search results, but sorting search results is not enabled by default. To give users the ability to sort their search results by item rank, date, or other available metadata, use the instructions below.

When sorting is made by rank in descending order, mixing algorithms should be used. Sort parameters are appended to your SmartHub URL, for example, https://<SmartHubResultsPage>#sort=date%20descending. This allows users to reload or share the results page while maintaining the specific sort parameters. Users can select the number of search results they want to receive on the search results page by using the RowsPerPage control. For more information, see Adding the Content Containers Module.

TabularView changes the display template for a specified ContentContainer. For more information, see View Query Results in a Tabular View.
To display the sort control on a results page that uses Tabular view, you must add the sort settings to the content container that has the tabular view enabled using the steps below. For example, if the tabular view is enabled for MainResults, the corresponding ContentContainer called MainResults will be modified by adding the sort settings.

Enabling sorting on a results page

UI Editor

To customize or enable sorting on a ContentContainer, you must use the UI Editor. For more information, see How to Use the UI Editor.

Procedure:

  1. SmartHub administrators can simply click the UI Editor link from the SmartHub Administration page.

  2. Select an HTML page such as Results.html page.

    1. The Results.html page is shown for sample purposes.

    2. BA Insight recommends that you use custom pages and folders to modify. Leave the default files as templates.

      1. Example: Customizations/Results.html. Default Results.html is under the top most SmartHub directory.

      2. See Creating Custom Pages.

  3. Select the Advanced mode from the top right of the page.

  4. Select Edit Settings.

  5. Locate the text SH.ContentContainers.CustomSettings on the settings page.

  6. Add the sorting properties to your desired ContentContainer. See the ShowSort and SortProperties parameters in the code snippet below:

    SH.ContentContainers = SH.ContentContainers || {};
    SH.ContentContainers.CustomSettings = {
        PreviousLabel: "Previous".toLocaleString(),
        NextLabel: "Next".toLocaleString(),
        SortLabel: "Sort by: ".toLocaleString(),
        CollapseLabel: "Collapse".toLocaleString(),
        ExpandLabel: "Expand".toLocaleString(),
        CloseLabel: "Close".toLocaleString(),
        NoResultsLabel: "Sorry, no results found!".toLocaleString(),
        UserProfileServiceURL: SH.RootLevelURL + "/_bai/v1.0/userprofile",
        ContentContainers: {
            SampleCBSWithDefaultValues: {
                ParentContainerSelector: '.sh-main-results-container',
                Title: '',
                Order:1,
                ControlTemplatePath: SH.RootLevelURL + "/modules/ContentContainers/newTemplates/collapsibleControlTemplate.html",
                ItemTemplatePicker: function (result) { return SH.RootLevelURL + "/modules/ContentContainers/newTemplates/itemTemplate.html"; },
                PaginationContainerSelector: ".sh-contentContainer-footer",
                PaginationTemplatePath: SH.RootLevelURL + "/modules/ContentContainers/templates/paginationTemplate.html",
                QueryTemplate: '{searchboxquery} FederatorBackends:"*"',
                SourceId: 'b29924a9-ec32-4c10-8892-a544b69ee121',
                ShowRowsPerPage: false,
                RowsPerPage: [10,20,50],                    
                RowsPerPageLabel: "Results per page: ".toLocaleString(),
                EnablePagination: false,
                EnableCountTotal: false,
                EnableSmartPreviews: true,
                EnableContentIntelligence: true,
                EnableResultFeedback: true,
                EnableRatings: false,
                EnablePubChemViewer: false,
                Baskets:{'.basketButton':true},                    
                AllowUserActivation: true,
                ShowSort: false,
                SortLabel: "Sort by: ".toLocaleString(),
                SortProperties: 'Rank#Most Relevant#descending,date#Newest#descending,date#Oldest#ascending',
                IsMainResults: false,
                RequiresTracking: false,
                FieldsToInclude: 'clickUri,title,Rank,ContentSource,FileExtension,excerpt,SDFUrl,date,DisplayAuthor,isUserProfile,WorkEmail,Title,JobTitle,Department,AboutMe,escbasecrawurl,UserName',
                TriggerNewQueryOn: 'deferredQuerySuccess',
                DeferredRendering:false
            },
            SampleMainResultsWithDefaultValues: {
                ParentContainerSelector: '.sh-main-results-container',
                Title: '',
                Order:1,
                ControlTemplatePath: SH.RootLevelURL + "/modules/ContentContainers/newTemplates/controlTemplate.html",
                ItemTemplatePicker: function (result) {
                    if (result.isError) return SH.RootLevelURL + "/modules/ContentContainers/newTemplates/errorTemplate.html";
                    if (result.isUserProfile == 'true') return SH.RootLevelURL + "/modules/ContentContainers/newTemplates/peopleTemplate.html";
                    if(result.isAuth) return SH.RootLevelURL + "/modules/ContentContainers/newTemplates/authTemplate.html";
                    return SH.RootLevelURL + "/modules/ContentContainers/newTemplates/itemTemplate.html";
                },
                PaginationContainerSelector: ".sh-contentContainer-footer",
                PaginationTemplatePath: SH.RootLevelURL + "/modules/ContentContainers/templates/paginationTemplate.html",
                SourceId: 'b29924a9-ec32-4c10-8892-a544b69ee121',
                ShowRowsPerPage: false,
                RequestedNumberOfResults:-1,
                RowsPerPage: [10,20,50],                    
                RowsPerPageLabel: "Results per page: ".toLocaleString(),
                EnablePagination: false,
                EnableCountTotal: false,
                EnableSmartPreviews: true,
                EnableContentIntelligence: true,
                EnableResultFeedback: true,
                EnableRatings: false,
                EnablePubChemViewer: false,
                Baskets:{'.basketButton':false},
                AllowUserActivation: false,
                ShowSort: false,
                SortLabel: "Sort by: ".toLocaleString(),
                SortProperties: 'Rank#Most Relevant#descending,date#Newest#descending,date#Oldest#ascending',
                RequiresTracking: false,
                FieldsToInclude: 'clickUri,title,Rank,ContentSource,FileExtension,excerpt,SDFUrl,date,DisplayAuthor,isUserProfile,WorkEmail,JobTitle,Department,AboutMe,escbasecrawurl,UserName',
                TriggerNewQueryOn: 'deferredQuerySuccess',
                IsMainResults: true,
                DeferredRendering:false
            }
        }
    }
    SH.ContentContainers.PathsToExclude = [
        //[ContentContainers,SampleCBSWithDefaultValues]
    ];
  1. To view all available settings, click the link Default Settings at the top right and scroll down to the line that contains the text SH.ContentContainers.DefaultSettings

  2. Update the following parameters:

    1. Set the ShowSort parameter to true to display the sort control on the container.

    2. Update SortProperties parameter to contain the desired sort properties, their labels, and the sort direction.

      • The SortProperties parameter use the following format: Property1#Label1#Direction1,Property2#Label2#Direction2.

      • If no direction is specified, descending order is used.

      • If no label is specified, it will use the property name.

      • By default, this parameter uses 'Rank#Most Relevant#descending,date#Newest#descending,date#Oldest#ascending'

    For more information, see Adding the content containers module.

  3. Save your configuration.